home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Actual 85 Febrero 2004.iso / Experto / Apache / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F251780_apr_time.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-05  |  9.8 KB  |  284 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_TIME_H
  56. #define APR_TIME_H
  57.  
  58. /**
  59.  * @file apr_time.h
  60.  * @brief APR Time Library
  61.  */
  62.  
  63. #include "apr.h"
  64. #include "apr_pools.h"
  65. #include "apr_errno.h"
  66.  
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif /* __cplusplus */
  70.  
  71. /**
  72.  * @defgroup apr_time Time Routines
  73.  * @ingroup APR 
  74.  * @{
  75.  */
  76.  
  77. /** month names */
  78. APR_DECLARE_DATA extern const char apr_month_snames[12][4];
  79. /** day names */
  80. APR_DECLARE_DATA extern const char apr_day_snames[7][4];
  81.  
  82.  
  83. /** number of microseconds since 00:00:00 january 1, 1970 UTC */
  84. typedef apr_int64_t apr_time_t;
  85.  
  86.  
  87. /** mechanism to properly type apr_time_t literals */
  88. #define APR_TIME_C(val) APR_INT64_C(val)
  89.  
  90. /** mechanism to properly print apr_time_t values */
  91. #define APR_TIME_T_FMT APR_INT64_T_FMT
  92.  
  93. /** intervals for I/O timeouts, in microseconds */
  94. typedef apr_int64_t apr_interval_time_t;
  95. /** short interval for I/O timeouts, in microseconds */
  96. typedef apr_int32_t apr_short_interval_time_t;
  97.  
  98. /** number of microseconds per second */
  99. #define APR_USEC_PER_SEC APR_TIME_C(1000000)
  100.  
  101. /** @return apr_time_t as a second */
  102. #define apr_time_sec(time) ((time) / APR_USEC_PER_SEC)
  103.  
  104. /** @return apr_time_t as a usec */
  105. #define apr_time_usec(time) ((time) % APR_USEC_PER_SEC)
  106.  
  107. /** @return apr_time_t as a msec */
  108. #define apr_time_msec(time) (((time) / 1000) % 1000)
  109.  
  110. /** @return apr_time_t as a msec */
  111. #define apr_time_as_msec(time) ((time) / 1000)
  112.  
  113. /** @return a second as an apr_time_t */
  114. #define apr_time_from_sec(sec) ((apr_time_t)(sec) * APR_USEC_PER_SEC)
  115.  
  116. /** @return a second and usec combination as an apr_time_t */
  117. #define apr_time_make(sec, usec) ((apr_time_t)(sec) * APR_USEC_PER_SEC \
  118.                                 + (apr_time_t)(usec))
  119.  
  120. /**
  121.  * @return the current time
  122.  */
  123. APR_DECLARE(apr_time_t) apr_time_now(void);
  124.  
  125. /** @see apr_time_exp_t */
  126. typedef struct apr_time_exp_t apr_time_exp_t;
  127.  
  128. /**
  129.  * a structure similar to ANSI struct tm with the following differences:
  130.  *  - tm_usec isn't an ANSI field
  131.  *  - tm_gmtoff isn't an ANSI field (it's a bsdism)
  132.  */
  133. struct apr_time_exp_t {
  134.     /** microseconds past tm_sec */
  135.     apr_int32_t tm_usec;
  136.     /** (0-61) seconds past tm_min */
  137.     apr_int32_t tm_sec;
  138.     /** (0-59) minutes past tm_hour */
  139.     apr_int32_t tm_min;
  140.     /** (0-23) hours past midnight */
  141.     apr_int32_t tm_hour;
  142.     /** (1-31) day of the month */
  143.     apr_int32_t tm_mday;
  144.     /** (0-11) month of the year */
  145.     apr_int32_t tm_mon;
  146.     /** year since 1900 */
  147.     apr_int32_t tm_year;
  148.     /** (0-6) days since sunday */
  149.     apr_int32_t tm_wday;
  150.     /** (0-365) days since jan 1 */
  151.     apr_int32_t tm_yday;
  152.     /** daylight saving time */
  153.     apr_int32_t tm_isdst;
  154.     /** seconds east of UTC */
  155.     apr_int32_t tm_gmtoff;
  156. };
  157.  
  158. /**
  159.  * convert an ansi time_t to an apr_time_t
  160.  * @param result the resulting apr_time_t
  161.  * @param input the time_t to convert
  162.  */
  163. APR_DECLARE(apr_status_t) apr_time_ansi_put(apr_time_t *result, 
  164.                                                     time_t input);
  165.  
  166. /**
  167.  * convert a time to its human readable components using an offset
  168.  * from GMT
  169.  * @param result the exploded time
  170.  * @param input the time to explode
  171.  * @param offs the number of seconds offset to apply
  172.  */
  173. APR_DECLARE(apr_status_t) apr_time_exp_tz(apr_time_exp_t *result,
  174.                                           apr_time_t input,
  175.                                           apr_int32_t offs);
  176.  
  177. /** @deprecated @see apr_time_exp_tz */
  178. APR_DECLARE(apr_status_t) apr_explode_time(apr_time_exp_t *result,
  179.                                            apr_time_t input,
  180.                                            apr_int32_t offs);
  181.  
  182. /**
  183.  * convert a time to its human readable components in GMT timezone
  184.  * @param result the exploded time
  185.  * @param input the time to explode
  186.  */
  187. APR_DECLARE(apr_status_t) apr_time_exp_gmt(apr_time_exp_t *result, 
  188.                                            apr_time_t input);
  189.  
  190. /**
  191.  * convert a time to its human readable components in local timezone
  192.  * @param result the exploded time
  193.  * @param input the time to explode
  194.  */
  195. APR_DECLARE(apr_status_t) apr_time_exp_lt(apr_time_exp_t *result, 
  196.                                           apr_time_t input);
  197.  
  198. /** @deprecated @see apr_time_exp_lt */
  199. APR_DECLARE(apr_status_t) apr_explode_localtime(apr_time_exp_t *result, 
  200.                                                 apr_time_t input);
  201.  
  202. /**
  203.  * Convert time value from human readable format to a numeric apr_time_t 
  204.  * e.g. elapsed usec since epoch
  205.  * @param result the resulting imploded time
  206.  * @param input the input exploded time
  207.  */
  208. APR_DECLARE(apr_status_t) apr_time_exp_get(apr_time_t *result, 
  209.                                            apr_time_exp_t *input);
  210.  
  211. /**
  212.  * Convert time value from human readable format to a numeric apr_time_t that
  213.  * always represents GMT
  214.  * @param result the resulting imploded time
  215.  * @param input the input exploded time
  216.  */
  217. APR_DECLARE(apr_status_t) apr_time_exp_gmt_get(apr_time_t *result, 
  218.                                                apr_time_exp_t *input);
  219.  
  220. /** @deprecated @see apr_time_exp_gmt_get */
  221. APR_DECLARE(apr_status_t) apr_implode_gmt(apr_time_t *result, 
  222.                                           apr_time_exp_t *input);
  223.  
  224. /**
  225.  * Sleep for the specified number of micro-seconds.
  226.  * @param t desired amount of time to sleep.
  227.  * @warning May sleep for longer than the specified time. 
  228.  */
  229. APR_DECLARE(void) apr_sleep(apr_interval_time_t t);
  230.  
  231. /** length of a RFC822 Date */
  232. #define APR_RFC822_DATE_LEN (30)
  233. /**
  234.  * apr_rfc822_date formats dates in the RFC822
  235.  * format in an efficient manner.  It is a fixed length
  236.  * format which requires the indicated amount of storage,
  237.  * including the trailing null byte.
  238.  * @param date_str String to write to.
  239.  * @param t the time to convert 
  240.  */
  241. APR_DECLARE(apr_status_t) apr_rfc822_date(char *date_str, apr_time_t t);
  242.  
  243. /** length of a CTIME date */
  244. #define APR_CTIME_LEN (25)
  245. /**
  246.  * apr_ctime formats dates in the ctime() format
  247.  * in an efficient manner.  it is a fixed length format
  248.  * and requires the indicated amount of storage including
  249.  * the trailing null byte.
  250.  * Unlike ANSI/ISO C ctime(), apr_ctime() does not include
  251.  * a \n at the end of the string.
  252.  * @param date_str String to write to.
  253.  * @param t the time to convert 
  254.  */
  255. APR_DECLARE(apr_status_t) apr_ctime(char *date_str, apr_time_t t);
  256.  
  257. /**
  258.  * formats the exploded time according to the format specified
  259.  * @param s string to write to
  260.  * @param retsize The length of the returned string
  261.  * @param max The maximum length of the string
  262.  * @param format The format for the time string
  263.  * @param tm The time to convert
  264.  */
  265. APR_DECLARE(apr_status_t) apr_strftime(char *s, apr_size_t *retsize, 
  266.                                        apr_size_t max, const char *format, 
  267.                                        apr_time_exp_t *tm);
  268.  
  269. /**
  270.  * Improve the clock resolution for the lifetime of the given pool.
  271.  * Generally this is only desireable on benchmarking and other very
  272.  * time-sensitive applications, and has no impact on most platforms.
  273.  * @param p The pool to associate the finer clock resolution 
  274.  */
  275. APR_DECLARE(void) apr_time_clock_hires(apr_pool_t *p);
  276.  
  277. /** @} */
  278.  
  279. #ifdef __cplusplus
  280. }
  281. #endif
  282.  
  283. #endif  /* ! APR_TIME_H */
  284.